<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>15.1.3 Unit Testing Domains 3.2.11</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen, print" title="Style" charset="utf-8"/>
    <link rel="stylesheet" href="../css/pdf.css" type="text/css" media="print" title="PDF" charset="utf-8"/>
    <script type="text/javascript">
function addJsClass() {
    var classes = document.body.className.split(" ");
    classes.push("js");
    document.body.className = classes.join(" ");
}
    </script>
</head>

<body class="body" onload="addJsClass();">
<div id="navigation">
    <div class="navTitle">
        
        The Grails Framework
    </div>
    <div class="navLinks">
        <ul>
            <li>
                <div id="nav-summary" onmouseover="toggleNavSummary(false)" onmouseout="toggleNavSummary(true)">
                    <a href="../../guide/index.html" class="button">Table of contents</a>

                    <div id="nav-summary-childs" style="display:none;">
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/introduction.html"><strong>1</strong><span>Introduction</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/gettingStarted.html"><strong>2</strong><span>Getting Started</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/upgrading.html"><strong>3</strong><span>Upgrading</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/conf.html"><strong>4</strong><span>Configuration</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/commandLine.html"><strong>5</strong><span>The Command Line</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/profiles.html"><strong>6</strong><span>Application Profiles</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/GORM.html"><strong>7</strong><span>Object Relational Mapping (GORM)</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/theWebLayer.html"><strong>8</strong><span>The Web Layer</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/traits.html"><strong>9</strong><span>Traits</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/webServices.html"><strong>10</strong><span>Web Services</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/async.html"><strong>11</strong><span>Asynchronous Programming</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/validation.html"><strong>12</strong><span>Validation</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/services.html"><strong>13</strong><span>The Service Layer</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/staticTypeCheckingAndCompilation.html"><strong>14</strong><span>Static Type Checking And Compilation</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/testing.html"><strong>15</strong><span>Testing</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/i18n.html"><strong>16</strong><span>Internationalization</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/security.html"><strong>17</strong><span>Security</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/plugins.html"><strong>18</strong><span>Plugins</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/spring.html"><strong>19</strong><span>Grails and Spring</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/hibernate.html"><strong>20</strong><span>Grails and Hibernate</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/scaffolding.html"><strong>21</strong><span>Scaffolding</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/deployment.html"><strong>22</strong><span>Deployment</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/contributing.html"><strong>23</strong><span>Contributing to Grails</span></a>
                        </div>
                        
                    </div>
                </div>
            </li>
            <li class="separator selected">
                <a id="ref-button" onclick="localToggle(); return false;" href="#">Quick Reference</a>
            </li>
        </ul>
    </div>


</div>

<table id="colset" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td id="col1">
            <div id="main" class="corner-all">

                
                    <div class="toc-item prev-left"><a href="../../guide/staticTypeCheckingAndCompilation.html">&lt;&lt; <strong>14</strong><span>Static Type Checking And Compilation</span></a></div>
                

                <span id='toggle-col1' class="toggle">(<a href="#" onclick="localToggle(); return false;">Quick Reference</a>)</span>

                
                    <div class="toc-item next-right"><a href="../../guide/i18n.html"><strong>16</strong><span>Internationalization</span> >></a></div>
                


                <div class="project">
                    <h1>15.1.3 Unit Testing Domains</h1>

                    <p><strong>Version:</strong> 3.2.11</p>
                </div>

                

                
<a name="12.1.3 Unit Testing Domains"><!-- Legacy link --></a>
<h2 id="unitTestingDomains">15.1.3 Unit Testing Domains</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/testing/unitTesting/unitTestingDomains.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect3">
<h4 id="_overview">Overview</h4>
<div class="paragraph">
<p>Domain class interaction can be tested without involving a real database connection using <code>DomainClassUnitTestMixin</code>.</p>
</div>
<div class="paragraph">
<p>The GORM implementation in DomainClassUnitTestMixin is using a simple in-memory <code>ConcurrentHashMap</code> implementation. Note that this has limitations compared to a real GORM implementation.</p>
</div>
<div class="paragraph">
<p>A large, commonly-used portion of the GORM API can be mocked using <code>DomainClassUnitTestMixin</code> including:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Simple persistence methods like <code>save()</code>, <code>delete()</code> etc.</p>
</li>
<li>
<p>Dynamic Finders</p>
</li>
<li>
<p>Named Queries</p>
</li>
<li>
<p>Query-by-example</p>
</li>
<li>
<p>GORM Events</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If you wish to test GORM using a real database then it is recommended to use one of the following super classes:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>grails.test.hibernate.HibernateSpec</code> - Sets up Hibernate for the current test</p>
</li>
<li>
<p><code>grails.test.mongodb.MongoSpec</code> - Sets up MongoDB for the current test</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>All features of GORM for Hibernate can be tested within a <code>HibernateSpec</code> unit test including:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>String-based HQL queries</p>
</li>
<li>
<p>composite identifiers</p>
</li>
<li>
<p>dirty checking methods</p>
</li>
<li>
<p>any direct interaction with Hibernate</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The implementation behind <code>HibernateSpec</code> takes care of setting up the Hibernate with the in-memory H2 database.</p>
</div>
</div>
<div class="sect3">
<h4 id="_domainclassunittestmixin_basics">DomainClassUnitTestMixin Basics</h4>
<div class="paragraph">
<p><code>DomainClassUnitTestMixin</code> is typically used in combination with testing either a controller, service or tag library where the domain is a mock collaborator defined by the <code>Mock</code> annotation:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.test.mixin.TestFor</span>
<span class="keyword">import</span> <span class="include">grails.test.mixin.Mock</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>

<span class="annotation">@TestFor</span>(BookController)
<span class="annotation">@Mock</span>(<span class="predefined-type">Book</span>)
<span class="type">class</span> <span class="class">BookControllerSpec</span> <span class="directive">extends</span> Specification {
    <span class="comment">// ...</span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The example above tests the <code>BookController</code> class and mocks the behavior of the <code>Book</code> domain class as well. For example consider a typical scaffolded <code>save</code> controller action:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">BookController</span> {
    <span class="keyword">def</span> <span class="function">save</span>() {
        <span class="keyword">def</span> book = <span class="keyword">new</span> <span class="predefined-type">Book</span>(params)
        <span class="keyword">if</span> (book.save(<span class="key">flush</span>: <span class="predefined-constant">true</span>)) {
            flash.message = message(
                    <span class="key">code</span>: <span class="string"><span class="delimiter">'</span><span class="content">default.created.message</span><span class="delimiter">'</span></span>,
                    <span class="key">args</span>: [message(<span class="key">code</span>: <span class="string"><span class="delimiter">'</span><span class="content">book.label</span><span class="delimiter">'</span></span>, <span class="keyword">default</span>: <span class="string"><span class="delimiter">'</span><span class="content">Book</span><span class="delimiter">'</span></span>), book.id])
            redirect(<span class="key">action</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">show</span><span class="delimiter">&quot;</span></span>, <span class="key">id</span>: book.id)
        }
        <span class="keyword">else</span> {
            render(<span class="key">view</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">create</span><span class="delimiter">&quot;</span></span>, <span class="key">model</span>: [<span class="key">bookInstance</span>: book])
        }
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Tests for this action can be written as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.test.mixin.TestFor</span>
<span class="keyword">import</span> <span class="include">grails.test.mixin.Mock</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>

<span class="annotation">@TestFor</span>(BookController)
<span class="annotation">@Mock</span>(<span class="predefined-type">Book</span>)
<span class="type">class</span> <span class="class">BookControllerSpec</span> <span class="directive">extends</span> Specification {
   <span class="type">void</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">test saving an invalid book</span><span class="delimiter">&quot;</span></span>() {
        <span class="key">when</span>:
        controller.save()

        <span class="key">then</span>:
        model.bookInstance != <span class="predefined-constant">null</span>
        view == <span class="string"><span class="delimiter">'</span><span class="content">/book/create</span><span class="delimiter">'</span></span>
    }

    <span class="type">void</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">test saving a valid book</span><span class="delimiter">&quot;</span></span>() {
        <span class="key">when</span>:
        params.title = <span class="string"><span class="delimiter">&quot;</span><span class="content">The Stand</span><span class="delimiter">&quot;</span></span>
        params.pages = <span class="string"><span class="delimiter">&quot;</span><span class="content">500</span><span class="delimiter">&quot;</span></span>

        controller.save()

        <span class="key">then</span>:
        response.redirectedUrl == <span class="string"><span class="delimiter">'</span><span class="content">/book/show/1</span><span class="delimiter">'</span></span>
        flash.message != <span class="predefined-constant">null</span>
        <span class="predefined-type">Book</span>.count() == <span class="integer">1</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>Mock</code> annotation also supports a list of mock collaborators if you have more than one domain to mock:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.test.mixin.TestFor</span>
<span class="keyword">import</span> <span class="include">grails.test.mixin.Mock</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>

<span class="annotation">@TestFor</span>(BookController)
<span class="annotation">@Mock</span>([<span class="predefined-type">Book</span>, Author])
<span class="type">class</span> <span class="class">BookControllerSpec</span> <span class="directive">extends</span> Specification {
    <span class="comment">// ...</span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Alternatively you can also use the <code>DomainClassUnitTestMixin</code> directly with the <code>TestMixin</code> annotation and then call the <code>mockDomain</code> method to mock domains during your test:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.test.mixin.TestFor</span>
<span class="keyword">import</span> <span class="include">grails.test.mixin.TestMixin</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>
<span class="keyword">import</span> <span class="include">grails.test.mixin.domain.DomainClassUnitTestMixin</span>

<span class="annotation">@TestFor</span>(BookController)
<span class="annotation">@TestMixin</span>(DomainClassUnitTestMixin)
<span class="type">class</span> <span class="class">BookControllerSpec</span> <span class="directive">extends</span> Specification {

    <span class="type">void</span> setupSpec() {
         mockDomain(<span class="predefined-type">Book</span>)
    }

    <span class="type">void</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">test saving an invalid book</span><span class="delimiter">&quot;</span></span>() {
        <span class="key">when</span>:
        controller.save()

        <span class="key">then</span>:
        model.bookInstance != <span class="predefined-constant">null</span>
        view == <span class="string"><span class="delimiter">'</span><span class="content">/book/create</span><span class="delimiter">'</span></span>
    }

    <span class="type">void</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">test saving a valid book</span><span class="delimiter">&quot;</span></span>() {
        <span class="key">when</span>:
        params.title = <span class="string"><span class="delimiter">&quot;</span><span class="content">The Stand</span><span class="delimiter">&quot;</span></span>
        params.pages = <span class="string"><span class="delimiter">&quot;</span><span class="content">500</span><span class="delimiter">&quot;</span></span>

        controller.save()

        <span class="key">then</span>:
        response.redirectedUrl == <span class="string"><span class="delimiter">'</span><span class="content">/book/show/1</span><span class="delimiter">'</span></span>
        flash.message != <span class="predefined-constant">null</span>
        <span class="predefined-type">Book</span>.count() == <span class="integer">1</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>mockDomain</code> method also includes an additional parameter that lets you pass a List of Maps to configure a domain, which is useful for fixture-like data:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">mockDomain(<span class="predefined-type">Book</span>, [
            [<span class="key">title</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">The Stand</span><span class="delimiter">&quot;</span></span>, <span class="key">pages</span>: <span class="integer">1000</span>],
            [<span class="key">title</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">The Shining</span><span class="delimiter">&quot;</span></span>, <span class="key">pages</span>: <span class="integer">400</span>],
            [<span class="key">title</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">Along Came a Spider</span><span class="delimiter">&quot;</span></span>, <span class="key">pages</span>: <span class="integer">300</span>] ])</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_testing_constraints">Testing Constraints</h4>
<div class="paragraph">
<p>There are 3 types of validateable classes:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Domain classes</p>
</li>
<li>
<p>Classes which implement the <code>Validateable</code> trait</p>
</li>
<li>
<p>Command Objects which have been made validateable automatically</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>These are all easily testable in a unit test with no special configuration necessary as long as the test method is marked with <code>TestFor</code> or explicitly applies the <code>GrailsUnitTestMixin</code> using <code>TestMixin</code>.  See the examples below.</p>
</div>
<div class="listingblock">
<div class="title">src/main/groovy/com/demo/MyValidateable.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="type">class</span> <span class="class">MyValidateable</span> <span class="directive">implements</span> grails.validation.Validateable {
    <span class="predefined-type">String</span> name
    <span class="predefined-type">Integer</span> age

    <span class="directive">static</span> constraints = {
        name <span class="key">matches</span>: <span class="regexp"><span class="delimiter">/</span><span class="content">[A-Z].*</span><span class="delimiter">/</span></span>
        age <span class="key">range</span>: <span class="integer">1</span>..<span class="integer">99</span>
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">grails-app/domain/com/demo/Person.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="type">class</span> <span class="class">Person</span> {
    <span class="predefined-type">String</span> name

    <span class="directive">static</span> constraints = {
        name <span class="key">matches</span>: <span class="regexp"><span class="delimiter">/</span><span class="content">[A-Z].*</span><span class="delimiter">/</span></span>
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/com/demo/DemoController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="type">class</span> <span class="class">DemoController</span> {

    <span class="keyword">def</span> <span class="function">addItems</span>(MyCommandObject co) {
        <span class="keyword">if</span>(co.hasErrors()) {
            render <span class="string"><span class="delimiter">'</span><span class="content">something went wrong</span><span class="delimiter">'</span></span>
        } <span class="keyword">else</span> {
            render <span class="string"><span class="delimiter">'</span><span class="content">items have been added</span><span class="delimiter">'</span></span>
        }
    }
}

<span class="type">class</span> <span class="class">MyCommandObject</span> {
    <span class="predefined-type">Integer</span> numberOfItems

    <span class="directive">static</span> constraints = {
        numberOfItems <span class="key">range</span>: <span class="integer">1</span>..<span class="integer">10</span>
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">test/unit/com/demo/PersonSpec.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="keyword">import</span> <span class="include">grails.test.mixin.TestFor</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>

<span class="annotation">@TestFor</span>(Person)
<span class="type">class</span> <span class="class">PersonSpec</span> <span class="directive">extends</span> Specification {

    <span class="type">void</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">Test that name must begin with an upper case letter</span><span class="delimiter">&quot;</span></span>() {
        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">the name begins with a lower letter</span><span class="delimiter">'</span></span>
        <span class="keyword">def</span> p = <span class="keyword">new</span> Person(<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">jeff</span><span class="delimiter">'</span></span>)

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validation should fail</span><span class="delimiter">'</span></span>
        !p.validate()

        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">the name begins with an upper case letter</span><span class="delimiter">'</span></span>
        p = <span class="keyword">new</span> Person(<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Jeff</span><span class="delimiter">'</span></span>)

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validation should pass</span><span class="delimiter">'</span></span>
        p.validate()
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">test/unit/com/demo/DemoControllerSpec.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="keyword">import</span> <span class="include">grails.test.mixin.TestFor</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>

<span class="annotation">@TestFor</span>(DemoController)
<span class="type">class</span> <span class="class">DemoControllerSpec</span> <span class="directive">extends</span> Specification {

    <span class="type">void</span> <span class="string"><span class="delimiter">'</span><span class="content">Test an invalid number of items</span><span class="delimiter">'</span></span>() {
        <span class="key">when</span>:
        params.numberOfItems = <span class="integer">42</span>
        controller.addItems()

        <span class="key">then</span>:
        response.text == <span class="string"><span class="delimiter">'</span><span class="content">something went wrong</span><span class="delimiter">'</span></span>
    }

    <span class="type">void</span> <span class="string"><span class="delimiter">'</span><span class="content">Test a valid number of items</span><span class="delimiter">'</span></span>() {
        <span class="key">when</span>:
        params.numberOfItems = <span class="integer">8</span>
        controller.addItems()

        <span class="key">then</span>:
        response.text == <span class="string"><span class="delimiter">'</span><span class="content">items have been added</span><span class="delimiter">'</span></span>
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">test/unit/com/demo/MyValidateableSpec.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="keyword">import</span> <span class="include">grails.test.mixin.TestMixin</span>
<span class="keyword">import</span> <span class="include">grails.test.mixin.support.GrailsUnitTestMixin</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>


<span class="annotation">@TestMixin</span>(GrailsUnitTestMixin)
<span class="type">class</span> <span class="class">MyValidateableSpec</span> <span class="directive">extends</span> Specification {

    <span class="type">void</span> <span class="string"><span class="delimiter">'</span><span class="content">Test validate can be invoked in a unit test with no special configuration</span><span class="delimiter">'</span></span>() {
        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">an object is valid</span><span class="delimiter">'</span></span>
        <span class="keyword">def</span> validateable = <span class="keyword">new</span> MyValidateable(<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Kirk</span><span class="delimiter">'</span></span>, <span class="key">age</span>: <span class="integer">47</span>)

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validate() returns true and there are no errors</span><span class="delimiter">'</span></span>
        validateable.validate()
        !validateable.hasErrors()
        validateable.errors.errorCount == <span class="integer">0</span>

        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">an object is invalid</span><span class="delimiter">'</span></span>
        validateable.name = <span class="string"><span class="delimiter">'</span><span class="content">kirk</span><span class="delimiter">'</span></span>

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validate() returns false and the appropriate error is created</span><span class="delimiter">'</span></span>
        !validateable.validate()
        validateable.hasErrors()
        validateable.errors.errorCount == <span class="integer">1</span>
        validateable.errors[<span class="string"><span class="delimiter">'</span><span class="content">name</span><span class="delimiter">'</span></span>].code == <span class="string"><span class="delimiter">'</span><span class="content">matches.invalid</span><span class="delimiter">'</span></span>

        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">the clearErrors() is called</span><span class="delimiter">'</span></span>
        validateable.clearErrors()

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">the errors are gone</span><span class="delimiter">'</span></span>
        !validateable.hasErrors()
        validateable.errors.errorCount == <span class="integer">0</span>

        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">the object is put back in a valid state</span><span class="delimiter">'</span></span>
        validateable.name = <span class="string"><span class="delimiter">'</span><span class="content">Kirk</span><span class="delimiter">'</span></span>

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validate() returns true and there are no errors</span><span class="delimiter">'</span></span>
        validateable.validate()
        !validateable.hasErrors()
        validateable.errors.errorCount == <span class="integer">0</span>
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">test/unit/com/demo/MyCommandObjectSpec.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="keyword">import</span> <span class="include">grails.test.mixin.TestMixin</span>
<span class="keyword">import</span> <span class="include">grails.test.mixin.support.GrailsUnitTestMixin</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>

<span class="annotation">@TestMixin</span>(GrailsUnitTestMixin)
<span class="type">class</span> <span class="class">MyCommandObjectSpec</span> <span class="directive">extends</span> Specification {

    <span class="type">void</span> <span class="string"><span class="delimiter">'</span><span class="content">Test that numberOfItems must be between 1 and 10</span><span class="delimiter">'</span></span>() {
        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">numberOfItems is less than 1</span><span class="delimiter">'</span></span>
        <span class="keyword">def</span> co = <span class="keyword">new</span> MyCommandObject()
        co.numberOfItems = <span class="integer">0</span>

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validation fails</span><span class="delimiter">'</span></span>
        !co.validate()
        co.hasErrors()
        co.errors[<span class="string"><span class="delimiter">'</span><span class="content">numberOfItems</span><span class="delimiter">'</span></span>].code == <span class="string"><span class="delimiter">'</span><span class="content">range.toosmall</span><span class="delimiter">'</span></span>

        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">numberOfItems is greater than 10</span><span class="delimiter">'</span></span>
        co.numberOfItems = <span class="integer">11</span>

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validation fails</span><span class="delimiter">'</span></span>
        !co.validate()
        co.hasErrors()
        co.errors[<span class="string"><span class="delimiter">'</span><span class="content">numberOfItems</span><span class="delimiter">'</span></span>].code == <span class="string"><span class="delimiter">'</span><span class="content">range.toobig</span><span class="delimiter">'</span></span>

        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">numberOfItems is greater than 1</span><span class="delimiter">'</span></span>
        co.numberOfItems = <span class="integer">1</span>

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validation succeeds</span><span class="delimiter">'</span></span>
        co.validate()
        !co.hasErrors()

        <span class="key">when</span>: <span class="string"><span class="delimiter">'</span><span class="content">numberOfItems is greater than 10</span><span class="delimiter">'</span></span>
        co.numberOfItems = <span class="integer">10</span>

        <span class="key">then</span>: <span class="string"><span class="delimiter">'</span><span class="content">validation succeeds</span><span class="delimiter">'</span></span>
        co.validate()
        !co.hasErrors()
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>That&#8217;s it for testing constraints. One final thing we would like to say is that testing the constraints in this way catches a common error: typos in the "constraints" property name which is a mistake that is easy to make and equally easy to overlook. A unit test for your constraints will highlight the problem straight away.</p>
</div>
</div>
<div class="sect3">
<h4 id="_hibernatespec_and_mongospec_basics">HibernateSpec and MongoSpec Basics</h4>
<div class="paragraph">
<p><code>HibernateSpec</code> allows Hibernate to be used in Grails unit tests. It uses a H2 in-memory database. The following documentation covers <code>HibernateSpec</code>, but the same concepts can be applied to <code>MongoSpec</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> example

<span class="keyword">import</span> <span class="include">grails.test.hibernate.HibernateSpec</span>
<span class="keyword">import</span> <span class="include">spock.lang.Specification</span>


<span class="type">class</span> <span class="class">PersonSpec</span> <span class="directive">extends</span> HibernateSpec {

    <span class="type">void</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">Test count people</span><span class="delimiter">&quot;</span></span>() {
        <span class="key">expect</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">Test execute Hibernate count query</span><span class="delimiter">&quot;</span></span>
            Person.count() == <span class="integer">0</span>
            sessionFactory != <span class="predefined-constant">null</span>
            transactionManager != <span class="predefined-constant">null</span>
            hibernateSession != <span class="predefined-constant">null</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>By default <code>HibernateSpec</code> will scan for domain classes within the package specified by the <code>grails.codegen.defaultPackage</code> configuration option or if not specified the same package as the test.</p>
</div>
</div>
<div class="sect3">
<h4 id="_configuring_domain_classes_for_hibernatespec_tests">Configuring domain classes for HibernateSpec tests</h4>
<div class="paragraph">
<p>If you only wish to test a limited set of domain classes you can override the <code>getDomainClasses</code> method to specify exactly which ones you wish to test:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> example

<span class="keyword">import</span> <span class="include">grails.test.hibernate.HibernateSpec</span>

<span class="type">class</span> <span class="class">PersonSpec</span> <span class="directive">extends</span> HibernateSpec {
    ...

    List&lt;<span class="predefined-type">Class</span>&gt; getDomainClasses() { [ Person ] }
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_testing_controllers_and_services_with_hibernatespec">Testing Controllers and Services with HibernateSpec</h4>
<div class="paragraph">
<p>If you wish to test a controller or a service with <code>HibernateSpec</code> generally you can combine <code>HibernateSpec</code> with Grails' default test mixins:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> example

<span class="keyword">import</span> <span class="include">grails.test.hibernate.HibernateSpec</span>

<span class="annotation">@TestFor</span>(BookController)
<span class="type">class</span> <span class="class">BookControllerUnitSpec</span> <span class="directive">extends</span> HibernateSpec {

    ...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>However, if the controller or service uses <code>@Transactional</code> you will need to assign the transaction manager within the unit test&#8217;s <code>setup</code> method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">setup</span>() {
    controller.transactionManager = transactionManager
}</code></pre>
</div>
</div>
</div>


                <div style="clear:both;margin-top:15px;"></div>
                
                    <div class="toc-item prev-left"><a href="../../guide/staticTypeCheckingAndCompilation.html">&lt;&lt; <strong>14</strong><span>Static Type Checking And Compilation</span></a></div>
                
                    <div class="toc-item next-right"><a href="../../guide/i18n.html"><strong>16</strong><span>Internationalization</span> >></a></div>
                
                <div style="clear:both"></div>
            </div>
        </td>
        <td id="col2">
            <div class="local clearfix">
                <div class="local-title">
                    <a href="../../guide/index.html" target="mainFrame">Quick Reference</a>
                    <span class="toggle">(<a href="#" onclick="localToggle(); return false;">hide</a>)</span>
                </div>
                <div class="menu">
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Command Line</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Command%20Line/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/bug-report.html">bug-report</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/clean.html">clean</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/compile.html">compile</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/console.html">console</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-app.html">create-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-command.html">create-command</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-controller.html">create-controller</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-domain-class.html">create-domain-class</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-functional-test.html">create-functional-test</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-hibernate-cfg-xml.html">create-hibernate-cfg-xml</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-integration-test.html">create-integration-test</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-interceptor.html">create-interceptor</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-plugin.html">create-plugin</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-profile.html">create-profile</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-script.html">create-script</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-service.html">create-service</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-taglib.html">create-taglib</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-unit-test.html">create-unit-test</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/dependency-report.html">dependency-report</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/docs.html">docs</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/generate-all.html">generate-all</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/generate-controller.html">generate-controller</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/generate-views.html">generate-views</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/help.html">help</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/install-templates.html">install-templates</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/list-plugins.html">list-plugins</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/list-profiles.html">list-profiles</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/package-plugin.html">package-plugin</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/package.html">package</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/plugin-info.html">plugin-info</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/profile-info.html">profile-info</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/run-app.html">run-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/run-command.html">run-command</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/run-script.html">run-script</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/schema-export.html">schema-export</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/shell.html">shell</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/stats.html">stats</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/stop-app.html">stop-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/test-app.html">test-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/war.html">war</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Constraints</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Constraints/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Constraints/attributes.html">attributes</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/bindable.html">bindable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/blank.html">blank</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/creditCard.html">creditCard</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/email.html">email</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/inList.html">inList</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/matches.html">matches</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/max.html">max</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/maxSize.html">maxSize</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/min.html">min</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/minSize.html">minSize</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/notEqual.html">notEqual</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/nullable.html">nullable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/range.html">range</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/scale.html">scale</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/size.html">size</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/unique.html">unique</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/url.html">url</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/validator.html">validator</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/widget.html">widget</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Controllers</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Controllers/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Controllers/actionName.html">actionName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/allowedMethods.html">allowedMethods</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/bindData.html">bindData</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/chain.html">chain</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/controllerName.html">controllerName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/defaultAction.html">defaultAction</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/errors.html">errors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/flash.html">flash</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/forward.html">forward</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/grailsApplication.html">grailsApplication</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/hasErrors.html">hasErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/namespace.html">namespace</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/params.html">params</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/redirect.html">redirect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/render.html">render</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/request.html">request</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/respond.html">respond</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/response.html">response</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/responseFormats.html">responseFormats</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/scope.html">scope</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/servletContext.html">servletContext</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/session.html">session</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/withForm.html">withForm</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/withFormat.html">withFormat</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Database Mapping</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/autoImport.html">autoImport</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/autoTimestamp.html">autoTimestamp</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/batchSize.html">batchSize</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/cache.html">cache</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/cascade.html">cascade</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/column.html">column</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/comment.html">comment</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/discriminator.html">discriminator</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/dynamicInsert.html">dynamicInsert</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/dynamicUpdate.html">dynamicUpdate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/fetch.html">fetch</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/id.html">id</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/ignoreNotFound.html">ignoreNotFound</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/indexColumn.html">indexColumn</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/insertable.html">insertable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/joinTable.html">joinTable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/lazy.html">lazy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/order.html">order</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/sort.html">sort</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/table.html">table</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/type.html">type</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/updateable.html">updateable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/version.html">version</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Domain Classes</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/addTo.html">addTo</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/attach.html">attach</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/belongsTo.html">belongsTo</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/clearErrors.html">clearErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/constraints.html">constraints</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/count.html">count</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/countBy.html">countBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/createCriteria.html">createCriteria</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/delete.html">delete</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/discard.html">discard</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/embedded.html">embedded</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/errors.html">errors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/executeQuery.html">executeQuery</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/executeUpdate.html">executeUpdate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/exists.html">exists</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/fetchMode.html">fetchMode</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/find.html">find</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findAll.html">findAll</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findAllBy.html">findAllBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findAllWhere.html">findAllWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findBy.html">findBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrCreateBy.html">findOrCreateBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrCreateWhere.html">findOrCreateWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrSaveBy.html">findOrSaveBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrSaveWhere.html">findOrSaveWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findWhere.html">findWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/first.html">first</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/get.html">get</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/getAll.html">getAll</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/getDirtyPropertyNames.html">getDirtyPropertyNames</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/getPersistentValue.html">getPersistentValue</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/hasErrors.html">hasErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/hasMany.html">hasMany</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/hasOne.html">hasOne</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/ident.html">ident</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/instanceOf.html">instanceOf</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/isAttached.html">isAttached</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/isDirty.html">isDirty</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/last.html">last</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/list.html">list</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/listOrderBy.html">listOrderBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/load.html">load</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/lock.html">lock</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/mapWith.html">mapWith</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/mappedBy.html">mappedBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/mapping.html">mapping</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/merge.html">merge</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/namedQueries.html">namedQueries</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/properties.html">properties</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/read.html">read</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/refresh.html">refresh</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/removeFrom.html">removeFrom</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/save.html">save</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/transients.html">transients</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/validate.html">validate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/where.html">where</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/whereAny.html">whereAny</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withCriteria.html">withCriteria</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withNewSession.html">withNewSession</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withSession.html">withSession</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withTransaction.html">withTransaction</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Plug-ins</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Plug-ins/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/URL%20mappings.html">URL mappings</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/codecs.html">codecs</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/controllers.html">controllers</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/core.html">core</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/dataSource.html">dataSource</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/domainClasses.html">domainClasses</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/hibernate.html">hibernate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/i18n.html">i18n</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/logging.html">logging</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/scaffolding.html">scaffolding</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/services.html">services</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/servlets.html">servlets</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Services</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Services/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Services/scope.html">scope</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Services/transactional.html">transactional</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Servlet API</h1><div class="menu-sub">
                        
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/request.html">request</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/response.html">response</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/servletContext.html">servletContext</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/session.html">session</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Tag Libraries</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/actionName.html">actionName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/controllerName.html">controllerName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/flash.html">flash</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/pageScope.html">pageScope</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/params.html">params</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/request.html">request</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/response.html">response</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/servletContext.html">servletContext</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/session.html">session</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Tags</h1><div class="menu-sub">
                        
                            
                            <div class="menu-item"><a href="../../ref/Tags/actionSubmit.html">actionSubmit</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/actionSubmitImage.html">actionSubmitImage</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/applyLayout.html">applyLayout</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/checkBox.html">checkBox</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/collect.html">collect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/cookie.html">cookie</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/country.html">country</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/countrySelect.html">countrySelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/createLink.html">createLink</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/createLinkTo.html">createLinkTo</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/currencySelect.html">currencySelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/datePicker.html">datePicker</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/each.html">each</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/eachError.html">eachError</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/else.html">else</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/elseif.html">elseif</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/external.html">external</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/field.html">field</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/fieldError.html">fieldError</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/fieldValue.html">fieldValue</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/findAll.html">findAll</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/form.html">form</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/formatBoolean.html">formatBoolean</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/formatDate.html">formatDate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/formatNumber.html">formatNumber</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/grep.html">grep</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/hasErrors.html">hasErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/header.html">header</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/hiddenField.html">hiddenField</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/if.html">if</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/img.html">img</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/include.html">include</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/isAvailable.html">isAvailable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/isNotAvailable.html">isNotAvailable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/javascript.html">javascript</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/join.html">join</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/layoutBody.html">layoutBody</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/layoutHead.html">layoutHead</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/layoutTitle.html">layoutTitle</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/link.html">link</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/localeSelect.html">localeSelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/message.html">message</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/meta.html">meta</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/pageProperty.html">pageProperty</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/paginate.html">paginate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/passwordField.html">passwordField</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/radio.html">radio</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/radioGroup.html">radioGroup</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/render.html">render</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/renderErrors.html">renderErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/resource.html">resource</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/select.html">select</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/set.html">set</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/sortableColumn.html">sortableColumn</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/submitButton.html">submitButton</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/textArea.html">textArea</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/textField.html">textField</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/timeZoneSelect.html">timeZoneSelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/unless.html">unless</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/uploadForm.html">uploadForm</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/while.html">while</a>
                            </div>
                            
                            </div>
                    </div>
                    
                </div>
            </div>
        </td>
    </tr>
</table>

<div id="footer">
    Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
    
</div>

<script type="text/javascript" src="../js/docs.js"></script>

</body>
</html>
